#!/bin/bash

# 确保repos.txt文件存在
if [ ! -f "repos.txt" ]; then
    echo "错误: repos.txt文件不存在，请先运行 get_repos.py 脚本"
    exit 1
fi

# 计数器
total=$(wc -l < repos.txt)
current=0
success=0
failed=0

# 读取每一行并克隆仓库
while IFS= read -r repo_url; do
    # 跳过空行
    if [ -z "$repo_url" ]; then
        continue
    fi
    
    current=$((current+1))
    
    # 从URL中提取仓库名称
    repo_name=$(basename "$repo_url" .git)
    
    echo "[$current/$total] 正在克隆: $repo_name ($repo_url)"
    
    # 克隆仓库
    if git clone "$repo_url"; then
        echo "✓ 成功克隆: $repo_name"
        success=$((success+1))
    else
        echo "✗ 克隆失败: $repo_name"
        failed=$((failed+1))
    fi
    
    echo "-----------------------------------"
done < repos.txt

echo "克隆完成: 共 $total 个仓库，成功 $success 个，失败 $failed 个" 